home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.10 Oct 88 / TransferSources / pack.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-05-22  |  5.1 KB  |  202 lines  |  [TEXT/MPS ]

  1. (*******************************************************************
  2.     
  3.     pack.pas
  4.     --------
  5.     
  6.     (c) 1987, 1988 Attic Software
  7.     
  8.     Pascal routines for PACK segment of Transfer
  9.     
  10. *******************************************************************)
  11.  
  12. unit pack;
  13.  
  14. (******************************************************************)
  15.  
  16.     interface
  17.     
  18. (******************************************************************)
  19.  
  20.     uses macintf, hfs, types;
  21.     
  22. (******************************************************************)
  23.  
  24.     implementation
  25.     
  26. (******************************************************************)
  27.  
  28.     procedure setglobal(value : long); external;
  29.     function getglobal : long; external;
  30.     procedure runiaz(iazaddr : long); external;
  31.     
  32. (*******************************************************************
  33.     
  34.     function systemdir
  35.     ------------------
  36.     
  37.     This routine is more or less straight out of Tech Note 67.  It
  38.     returns a directory id for the System folder, suitable for use
  39.     in “SetVol” calls.
  40.     
  41.     Step one is to find the volume reference number of the volume
  42.     that holds the System folder.  “sysmap” is the file reference
  43.     number of the System file (an open file), so “GetVRefNum” will
  44.     find the volume refence number of the System file and, of course,
  45.     the System folder.  (The Tech Note skips this step; it searches
  46.     the boot drive for a System folder, and may not find one.)
  47.     
  48.     Step two is to get the directory id, with a call to “PBHGetVInfo”.
  49.     The directory id is returned in the “ioVFndrInfo[1]” field of the
  50.     HParamBlockRec.
  51.     
  52. *******************************************************************)
  53.  
  54.     function systemdir(globals : wpointer) : long;
  55.         
  56.         var
  57.             thepointer        :    shortpointer;
  58.             thevolume        :    integer;
  59.             anerror            :    integer;
  60.         
  61.         begin
  62.             
  63.             with globals^ do begin
  64.                 
  65.                 thepointer := shortpointer(sysmap);
  66.                 anerror := GetVRefNum(thepointer^, thevolume);
  67.                 
  68.                 with hblock do begin
  69.                     ioNamePtr := nil;
  70.                     ioVRefNum := thevolume;
  71.                     ioVolIndex := 0;
  72.                 end;
  73.                 anerror := PBHGetVInfo(@hblock, false);
  74.                 
  75.                 systemdir := hblock.ioVFndrInfo[1];
  76.                 
  77.             end;
  78.         
  79.         end;
  80.  
  81. (*******************************************************************
  82.     
  83.     function setdir
  84.     ---------------
  85.     
  86.     This is just a shell around “PBHSetVol”.
  87.     
  88. *******************************************************************)
  89.  
  90.     function setdir(dirid : long; globals : wpointer) : OSErr;
  91.         
  92.         begin
  93.             
  94.             with globals^ do begin
  95.                 
  96.                 with wdblock do begin
  97.                     ioCompletion := nil;
  98.                     ioNamePtr := nil;
  99.                     ioVRefNum := 0;
  100.                     ioWDDirID := dirid;
  101.                 end;
  102.                 
  103.                 setdir := PBHSetVol(@wdblock, false);
  104.                 
  105.             end;
  106.         
  107.         end;
  108.     
  109. (*******************************************************************
  110.     
  111.     procedure postlaunch
  112.     --------------------
  113.     
  114.     This is the routine that performs the actual launch.  It is called
  115.     by “InitApplZone” throught the “iaznotify” hook.
  116.     
  117.     First, recover the global record with a call to “getglobal”.  This
  118.     routine is called after all the resources have been released; the
  119.     DRVR segment is no longer around, and even if it was, “postlaunch”
  120.     isn't called by it, so we can't find the globals in the usual way.
  121.     “getglobal” will return a long word stored right in the PACK
  122.     segment, which has been previously set to a pointer to the
  123.     globals.
  124.     
  125.     Next, “postlaunch” will call any routines that were already
  126.     installed in “iaznotify” when “postlaunch” was installed there,
  127.     via the “runiaz” routine.
  128.     
  129.     Then it calls “setdir” to set the volume to the folder containing
  130.     the chosen application, and copies the applications's name to
  131.     “curappname”.  The system will now be fooled into launching that
  132.     application instead of the FInder.
  133.     
  134. *******************************************************************)
  135.  
  136.     procedure postlaunch;
  137.         
  138.         var
  139.             globals            :    wpointer;
  140.             anerror            :    integer;
  141.         
  142.         begin
  143.             
  144.             globals := wpointer(getglobal);
  145.             with globals^ do begin
  146.                 runiaz(iazaddr);
  147.                 anerror := setdir(launchpath, globals);
  148.                 if anerror = noErr then
  149.                     BlockMove(@thename, Ptr(curappname), 32);
  150.             end;
  151.             
  152.         end;
  153.         
  154. (*******************************************************************
  155.     
  156.     procedure initglobals
  157.     ---------------------
  158.     
  159.     Initialize global data.  Note that we preserve the value at
  160.     “iaznotify”; if the current application has installed a routine
  161.     there, we will want to run it before we run ours.
  162.     
  163.     Also, we don't want to confuse the new application with the old
  164.     applications's data files, so we clear the finder files.
  165.     
  166. *******************************************************************)
  167.  
  168.     procedure initglobals(globals : wpointer);
  169.         
  170.         var
  171.             thepointer        :    longpointer;
  172.             message            :    integer;
  173.             count                :    integer;
  174.             index                :    integer;
  175.         
  176.         begin
  177.             
  178.             setglobal(long(globals));
  179.             
  180.             with globals^ do begin
  181.             
  182.                 sysdir := systemdir(globals);
  183.                 
  184.                 thepointer := longpointer(iaznotify);
  185.                 iazaddr := thepointer^;
  186.                 
  187.                 launchaddr := BitAnd(long(@postlaunch), $FFFFFF);
  188.             
  189.             end;
  190.             
  191.             CountAppFiles(message, count);
  192.             for index := 1 to count do
  193.                 ClrAppFiles(index);
  194.         
  195.         end;
  196.     
  197. (******************************************************************)
  198.             
  199.     end.
  200.     
  201. (******************************************************************)
  202.